#!/bin/sh -e
#install nac_clt_starter_Mac.py to /usr/local/bin

OS=`uname`
if [ "x$OS" = "xDarwin" ]; then
    INSTALL_DIR="/usr/local/bin"

    #install script to keep crankd always on
    KEEPALIVE="/Library/LaunchDaemons/net.ndn.keepalive.crankd.plist"
    if [ ! -f $KEEPALIVE ]; then
        cp config/net.ndn.keepalive.crankd.plist $KEEPALIVE
        echo "File $KEEPALIVE is created"
    else
        echo "File $KEEPALIVE already exists!"
        read -p "Do you want to overwrite it? (y or n)" ans2
        if [ $ans2 = "y" ]; then
            cp config/net.ndn.keepalive.crankd.plist $KEEPALIVE
            echo "File $KEEPALIVE is created!"
        fi
    fi
  
    #install script to run nac_client
    CLTLAUNCHER="/Library/Preferences/net.ndn.nac_client.crankd.plist"
    if [ ! -f $CLTLAUNCHER ]; then
        cp config/net.ndn.nac_client.crankd.plist $CLTLAUNCHER
        echo "File $CLTLAUNCHER is created"
    else
        echo "File $CLTLAUNCHER already exists!"
        read -p "Do you want to overwrite it? (y or n)" ans3
        if [ $ans3 = "y" ]; then
            cp config/net.ndn.nac_client.crankd.plist $CLTLAUNCHER
            echo "File $CLTLAUNCHER is created!"
        fi
    fi

    test -d /opt/nac || mkdir -p /opt/nac
    #install join_ndn.conf
    NAC_CFILE=/opt/nac/join_ndn.conf
    if [ ! -f $NAC_CFILE ]; then
        cp template/join_ndn.conf /opt/nac
        echo "File $NAC_CFILE is created!"
    else
        echo "File $NAC_CFILE already exists!"
        read -p "Do you want to overwrite it?(y or n)" ans4
        if [ $ans4 = "y" ]; then
            cp template/join_ndn.conf /opt/nac
            echo "File $NAC_CFILE is created!"
        fi
    fi

    #let user specify the home domain
    read -p "Please specify your home domain.(type 'none' if you don't have)" myhome
    if [ x"$myhome" != "xnone" ]; then
        echo $myhome >> $NAC_CFILE
    fi
fi



